package 二叉树;

/**
 * @ClassName _108将有序数组转换为二叉搜索树
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2021/10/5 20:14
 * Version 1.0
 **/
public class _108将有序数组转换为二叉搜索树 {
    public TreeNode sortedArrayToBST(int[] nums) {
        return fun(nums,0,nums.length - 1);
    }
    public TreeNode fun(int[] nums,int low,int high){
        if(low > high){
            return null;
        }
        int mid = (high + low)/2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = fun(nums,low,mid -1);
        root.right = fun(nums,mid + 1, high);
        return root;
    }
}
